home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / AmiTCP30b2.lha / src / appl / napsaterm / beep.c < prev    next >
C/C++ Source or Header  |  1994-05-17  |  2KB  |  69 lines

  1. RCS_ID_C "$Id: beep.c,v 3.2 1994/05/16 22:13:18 ppessi Exp $";
  2. /*
  3.  * Most of this was stolen from the "beep" program from the Manx 3.6a
  4.  * distribution.
  5.  */
  6.  
  7. #include <string.h>
  8.  
  9. #include "amiga.h"
  10. #include "display.h"
  11.  
  12. #include <devices/audio.h>
  13. #include <clib/alib_protos.h>
  14.  
  15. UBYTE allocmap[] = { 1, 8, 2, 4 };
  16. #ifdef USE_CHIP
  17. CHIP UBYTE wave[] = { 69, 116, 126, 96, 36, 220, 160, 130, 140, 0 };
  18. #else
  19. UBYTE bwave[] = { 69, 116, 126, 96, 36, 220, 160, 130, 140, 0 };
  20. #endif
  21.  
  22. void audiobell(void)
  23. {
  24.     struct MsgPort *mp = NULL;
  25.     struct IOAudio *ar = NULL;
  26. #ifndef USE_CHIP
  27.     UBYTE *wave = NULL;
  28. #endif
  29.  
  30.     if (!(mp = CreateMsgPort()) ||
  31. #ifndef USE_CHIP
  32.        !(wave = (UBYTE *)AllocMem(sizeof(bwave), MEMF_CHIP)) ||
  33. #endif
  34.        !(ar = (struct IOAudio *)CreateIORequest(mp, sizeof(*ar)))) {
  35.         dsinvert(VISUAL_BELL);
  36.     goto CleanReturn;
  37.     }
  38. #ifndef USE_CHIP
  39.     memcpy(wave, bwave, sizeof(bwave));
  40. #endif
  41.     ar->ioa_Request.io_Message.mn_Node.ln_Pri = 20;
  42.     ar->ioa_Data = allocmap;
  43.     ar->ioa_Length = sizeof(allocmap);
  44.     if (OpenDevice(AUDIONAME, 0, (struct IORequest *)ar, 0) == 0) {
  45.         ar->ioa_Request.io_Command = CMD_WRITE;
  46.     ar->ioa_Request.io_Flags = ADIOF_PERVOL;
  47.     ar->ioa_Data = wave;
  48.         ar->ioa_Length = 10;
  49.     ar->ioa_Period = 421;
  50.         ar->ioa_Volume = 64;
  51.     ar->ioa_Cycles = 100;
  52.  
  53.     /* 
  54.      * We must use BeginIO/WaitIO pair, since
  55.      * DoIO/SendIO mangle the io_Flags
  56.      */
  57.     BeginIO((struct IORequest *)ar);
  58.     WaitIO((struct IORequest *)ar);
  59.     CloseDevice((struct IORequest *)ar);
  60.     } else dsinvert(VISUAL_BELL);
  61.  
  62.  CleanReturn:
  63. #ifndef USE_CHIP
  64.     if (wave) FreeMem(wave, sizeof(bwave)), wave = NULL;
  65. #endif
  66.     if (ar) DeleteIORequest((struct IORequest *)ar), ar = NULL;
  67.     if (mp) DeleteMsgPort(mp), mp = NULL;
  68. }
  69.